package com.halixun.d2app.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.halixun.d2app.R;
import com.halixun.d2app.app.MyApplication;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.utils
 * @ClassName: ToastUtils
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/11/28 18:08
 * @UpdateUser: hdx
 * @UpdateDate: 2019/11/28 18:08
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class ToastUtils {
    private static Toast mToast;

    @SuppressLint("ShowToast")
    public synchronized static void showToast(Context context, String content, int gravity) {
        if (content == null) return;
        if (mToast == null) {
            mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
        }
        ViewGroup parentView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.toast_layout,null);
        TextView textView = parentView.findViewById(R.id.toast_message);
        textView.setText(content);
        mToast.setGravity(gravity, 0, 0);
        mToast.setView(parentView);
        mToast.show();
    }

    public synchronized static void showToast(int content, int gravity) {
        Context context = MyApplication.getMyContext();
        showToast(context, context.getString(content), gravity);
    }

    public synchronized static void showToast(int content) {
        Context context = MyApplication.getMyContext();
        showToast(context, context.getString(content), Gravity.CENTER);
    }

    public synchronized static void showToast(String content) {
        showToast(MyApplication.getMyContext(), content, Gravity.CENTER);
    }

    public synchronized static void showCenterToast(String content) {
        showToast(MyApplication.getMyContext(), content, Gravity.CENTER);
    }

    public synchronized static void showCenterToast(int content) {
        Context context = MyApplication.getMyContext();
        showToast(context, context.getString(content), Gravity.CENTER);
    }

    public synchronized static void showBottomToast(String content) {
        showToast(MyApplication.getMyContext(), content, Gravity.BOTTOM);
    }

    public synchronized static void showBottomToast(int content) {
        Context context = MyApplication.getMyContext();
        showToast(context, context.getString(content), Gravity.BOTTOM);
    }
}
